home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / graphicgems4.lha / GemsIV / graph_layout / vector.hxx < prev    next >
Encoding:
Text File  |  1995-02-06  |  1.2 KB  |  33 lines

  1. /****************************************************************************
  2. **    TEST FILE FOR graph (Dynamic Layout Alg)
  3. **
  4. **    HEADER   - 2D VECTOR OPERATIONS
  5. **
  6. ** Author: dr. Szirmay-Kalos Laszlo (szirmay@fsz.bme.hu)
  7. **       Technical University of Budapest, Hungary
  8. *****************************************************************************/
  9. /*
  10. *    VECTOR - 2D GEOMETRIC VECTOR TYPE
  11. */
  12. class     vector {
  13.     double x;                     // coordinates
  14.     double y;
  15. public:
  16.     vector()                 { x = 0.0; y = 0.0;          }
  17.     vector(double x0, double y0)     { x = x0; y = y0;              }
  18.     void     operator=(vector&    a)   { x = a.x; y = a.y;          }
  19.     void     operator+=(vector& a)   { x += a.x; y += a.y;          }
  20.     void     operator/=(double d)    { if (d != 0.0) {x /= d; y /= d;}}
  21.     void     operator*=(double d)    { x *= d; y *= d;              }
  22.     double      X()             { return x;              }
  23.     double      Y()             { return y;              }
  24.     double     Size();
  25.  
  26. // FRIENDS
  27.     friend vector operator+(vector&, vector&);
  28.     friend vector operator-(vector&, vector&);
  29.     friend vector operator-(vector&);
  30.     friend vector operator*(vector&, double);
  31.     friend vector operator*(double, vector&);
  32. };
  33.